package hotel.service;

import java.util.HashMap;
import java.util.Map;

import hotel.dao.DaoManager;
import hotel.service.impl.RequestServiceImpl;
import hotel.service.impl.RoomServiceImpl;
import hotel.service.impl.UserServiceImpl;
//import hotel.service.impl.RoomServiceImpl;
//import hotel.service.impl.RequestServiceImpl;

// use this class from action by ServiceManager.getDefault()
public class ServiceManager {

	@SuppressWarnings("rawtypes")
	private Map<Class, Object> serviceObjects;
	private DaoManager daoManager;
	
	private ServiceManager() {
		super();
		this.init();
	}
	
	protected DaoManager getDaoManager() {
		return daoManager;
	}

	public static ServiceManager getDefault() {
		return new ServiceManager();
	}

	@SuppressWarnings("rawtypes")
	private void init() {
		daoManager = DaoManager.getDefault();
		serviceObjects = new HashMap<Class, Object>();
		
		serviceObjects.put(UserService.class, new UserServiceImpl(getDaoManager()));
		serviceObjects.put(RoomService.class, new RoomServiceImpl(getDaoManager()));
		serviceObjects.put(RequestService.class, new RequestServiceImpl(getDaoManager()));
	}

	public UserService getUserService() 
	{
		return (UserService) serviceObjects.get(UserService.class);
	}
	
	public RoomService getRoomService() 
	{
		return (RoomService) serviceObjects.get(RoomService.class);
	}

	public RequestService getRequestService() 
	{
		return (RequestService) serviceObjects.get(RequestService.class);
	}

}